package simonby.top.annualring.infrastructure.repository;

import simonby.top.annualring.domain.model.UserFamily;
import simonby.top.annualring.domain.repository.UserFamilyRepository;
import org.springframework.stereotype.Repository;
import simonby.top.annualring.infrastructure.dao.UserFamilyDao;

import java.util.List;
import java.util.Optional;

/**
 * 用户家族关联仓储的实现
 */
@Repository
public class UserFamilyRepositoryImpl implements UserFamilyRepository {
    private final UserFamilyDao userFamilyDao;

    public UserFamilyRepositoryImpl(UserFamilyDao userFamilyDao) {
        this.userFamilyDao = userFamilyDao;
    }

    @Override
    public UserFamily save(UserFamily userFamily) {
        return userFamilyDao.save(userFamily);
    }

    @Override
    public Optional<UserFamily> findById(Long id) {
        return userFamilyDao.findById(id);
    }

    @Override
    public List<UserFamily> findByUserId(Long userId) {
        return userFamilyDao.findByUserId(userId);
    }

    @Override
    public List<UserFamily> findByFamilyTreeId(Long familyTreeId) {
        return userFamilyDao.findByFamilyTreeId(familyTreeId);
    }

    @Override
    public List<UserFamily> findAll() {
        return userFamilyDao.findAll();
    }

    @Override
    public void deleteById(Long id) {
        userFamilyDao.deleteById(id);
    }

    @Override
    public Optional<UserFamily> findByUserIdAndFamilyTreeId(Long userId, Long familyTreeId) {
        return userFamilyDao.findByUserIdAndFamilyTreeId(userId, familyTreeId);
    }
}